package com.huawei.hms.framework.network.restclient.hwhttp.trans;

import com.huawei.hms.framework.common.IoUtils;
import com.huawei.hms.framework.common.Logger;
import com.huawei.hms.framework.network.restclient.hwhttp.RequestBody;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InterruptedIOException;
import java.io.OutputStream;
import javax.annotation.Nullable;
import o.fup;
import o.fuw;
import o.fxj;

public class OkRequestBody extends fuw {
    private static final String TAG = "OkRequestBody";
    private RequestBody requestBody;

    public OkRequestBody(RequestBody requestBody) {
        this.requestBody = requestBody;
    }

    @Nullable
    public fup contentType() {
        if (this.requestBody.contentType() == null) {
            return null;
        }
        return fup.ॱ(this.requestBody.contentType());
    }

    public long contentLength() throws IOException {
        return this.requestBody.contentLength() == 0 ? -1 : this.requestBody.contentLength();
    }

    public void writeTo(fxj o_fxj) throws IOException {
        OutputStream okhttpOutputStream = new OkhttpOutputStream(o_fxj);
        try {
            this.requestBody.writeTo(okhttpOutputStream);
            IoUtils.closeSecure(okhttpOutputStream);
        } catch (FileNotFoundException e) {
            Logger.w(TAG, "the requestBody with writeTo has error! and the FileNotFound must be changed to InterruptedIOException");
            throw new InterruptedIOException(e.getMessage());
        } catch (IOException e2) {
            Logger.w(TAG, "the requestBody with writeTo has other error");
            throw e2;
        }
    }
}
